package servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspWriter;

import Model.Staff;

/**
 * Servlet implementation class RoleTable
 */
@WebServlet("/RoleStaffDropdown")
public class RoleStaffDropdown extends HttpServlet {
	private static final long serialVersionUID = 1L;
    JspWriter out;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RoleStaffDropdown() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    public RoleStaffDropdown(JspWriter outputStream) {
		// TODO Auto-generated constructor stub
		out = outputStream;
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		javax.servlet.http.HttpSession session = request.getSession();
		if (session.getAttribute("username")==null)
		{
			request.getRequestDispatcher("nopermission.jsp").forward(request,response);
		}
		else {
			String currentUser = session.getAttribute("username").toString();
			
			ArrayList<Staff> staffTable = new ArrayList<Staff>();
			staffTable = Database.StaffDB.getRoleTable();
			
			for(int i = 0; i < staffTable.size(); i++)
			{
				if(!currentUser.equals(staffTable.get(i).getId()))
				{
					out.print("<option value='" + staffTable.get(i).getId() + "'>");
						out.print(staffTable.get(i).getName() + " (" + staffTable.get(i).getRole() + ")");
					out.print("</option>");
				}
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
